package com.hu.common.util.adm;


import com.hu.common.enums.MessageEnum;
import com.hu.common.exception.BizException;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;

import java.util.Collection;


/**
 * @author 00355760
 */
public class Assert {

    public static void notEmpty(Object object, String msg) throws BizException {
        isTrue(ObjectUtils.isEmpty(object), msg);
    }

    public static boolean notEmptyCollection(Collection<?> collection) throws BizException {
        return !CollectionUtils.isEmpty(collection);
    }
    public static boolean isEmptyCollection(Collection<?> collection) throws BizException {
        return !notEmptyCollection(collection);
    }

    public static boolean notEmpty(Object object) {
        return !ObjectUtils.isEmpty(object);
    }

    public static boolean isEmpty(Object object) {
        return ObjectUtils.isEmpty(object);
    }

    public static void isTrue(boolean expression, String msg) throws BizException {
        if (expression) {
            throw new BizException(MessageEnum.FAIL.getCode(), msg);
        }
    }

    public static void notTrue(boolean expression, String msg) throws BizException {
        if (!expression) {
            throw new BizException(MessageEnum.FAIL.getCode(), msg);
        }
    }

}
